/*--------------------------------------------------------------------------------*/
#ifndef __INTERFACE_TEXT_BUTTON__
#define __INTERFACE_TEXT_BUTTON__
/*--------------------------------------------------------------------------------*/
#include "primitives.h"
#include "interface_object.h"
#include "util.h"
#include "graphic_2d_animated_object.h"
#include "graphic_text.h"
#include "graphic_font_manager.h"
#include "graphic_animation_manager.h"
/*--------------------------------------------------------------------------------*/
class INTERFACE_TEXT_BUTTON : public INTERFACE_OBJECT
{

	// -- PUBLIC

public:

    DECLARE_REF( INTERFACE_TEXT_BUTTON );

    // .. CONSTRUCTORS

    INTERFACE_TEXT_BUTTON() :
    	INTERFACE_OBJECT(),
    	GraphicText(),
    	GraphicObject(),
    	DefaultAnimation(),
    	SelectedAnimation()
    {

    }

    ~INTERFACE_TEXT_BUTTON()
    {
     
    }

    // .. METHODS

    VOID Initialize( const PROPERTY_TABLE & properties )
    {
    	INTERFACE_OBJECT::Initialize( properties );

    	GraphicText.SetText( properties.GetText( "text" ) );
    	GraphicText.SetExtentPerChar( properties.GetVector2( "char_extent" ) );
    	GraphicText.SetFont( GRAPHIC_FONT_MANAGER::GetInstance().GetFont( properties.GetText( "font" ) ) );

    	GraphicText.Update( 0 );

    	GraphicText.SetPosition( Position );
    	GraphicObject.SetPosition( Position );
		GraphicObject.SetExtent( Extent );

		DefaultAnimation = GRAPHIC_ANIMATION_MANAGER_GetAnimation( properties.GetText( "animation" ) );
		SelectedAnimation = GRAPHIC_ANIMATION_MANAGER_GetAnimation( properties.GetText( "selected_animation" ) );

		GraphicObject.SetAnimation( DefaultAnimation );
    }

    VOID Initialize(
    		const TEXT & text,
    		const MATH_VECTOR_2 & position,
    		const MATH_VECTOR_2 & extent,
    		const GRAPHIC_FONT & font,
    		const GRAPHIC_ANIMATION_DATA::REF & default_animation,
    		const GRAPHIC_ANIMATION_DATA::REF & selected_animation,
    		const MATH_VECTOR_2 & extent_per_char = MATH_VECTOR_2::Zero
    		)
    {
    	Extent = extent;
    	Position = position;

    	GraphicText.SetPosition( position );

    	if( !extent_per_char.IsZero() )
    	{
    		GraphicText.SetExtentPerChar( extent_per_char );
    	}
    	else
    	{
    		GraphicText.SetExtent( extent );
    	}

    	GraphicText.SetText( text );
    	GraphicText.SetFont( font );
    	GraphicText.Update( 0 );

    	GraphicObject.SetPosition( position );
    	GraphicObject.SetExtent( extent );

		DefaultAnimation = default_animation;
		SelectedAnimation = selected_animation;

		GraphicObject.SetAnimation( DefaultAnimation );
    }

    virtual VOID Update( const TIMER & timer )
    {
    	GraphicObject.Update( timer );
    }

    virtual VOID Render()
	{
    	if( ItIsVisible )
    	{
			GraphicObject.Render();
			GraphicText.Render();
    	}
	}
	
	virtual VOID OnSelectionChanged()
	{
		if( ItIsSelected )
		{
			GraphicObject.SetAnimation( SelectedAnimation );
		}	
		else
		{
			GraphicObject.SetAnimation( DefaultAnimation );
		}
	}	
	
	const TEXT & GetText() const 
	{
		return GraphicText.GetText();
	}

    // -- PRIVATE

private :

    // .. ATTRIBUTES

    GRAPHIC_TEXT
    	GraphicText;
    GRAPHIC_2D_ANIMATED_OBJECT
    	GraphicObject;
    GRAPHIC_ANIMATION_DATA::REF
    	DefaultAnimation,
    	SelectedAnimation;

    
};
/*--------------------------------------------------------------------------------*/
#endif
